import axios from '@/utils/request'

/**
 * 发送验证码
 * @param mobile 手机号
 * @returns {AxiosPromise}
 */
export const sendCode = mobile => {
  return axios({
    url: '/v1_0/sms/codes/' + mobile
  })
}

/**
 * 登录
 * @param {Object} data {mobile,code}
 * @returns {AxiosPromise}
 */
export const login = data => {
  return axios({
    url: '/v1_0/authorizations',
    method: 'POST',
    data
  })
}

/**
 * 获取用户信息
 * @returns {AxiosPromise}
 */
export function getUserInfo () {
  return axios({
    url: '/v1_0/user',
    method: 'GET'
  })
}

/**
 * 获取用户频道数据
 * @returns Promise
 */
export function getUserChannels () {
  return axios({
    url: '/v1_0/user/channels',
    method: 'GET'
  })
}

/**
 * 添加用户关注
 * @param {String} target
 * @returns {AxiosPromise}
 */
export function addFollowUser (target) {
  return axios({
    url: '/v1_0/user/followings',
    method: 'post',
    data: {
      target
    }
  })
}

/**
 * 取消关注
 * @param {String} target
 * @returns {AxiosPromise}
 */
export function removeFollowUser (target) {
  return axios({
    url: '/v1_0/user/followings/' + target,
    method: 'DELETE'
  })
}

/**
 * 获取用户信息
 * @returns {AxiosPromise}
 */
export function getUserProfile () {
  return axios({
    url: '/v1_0/user/profile'
  })
}

/**
 * 编辑用户资料
 * @param data
 * @returns {AxiosPromise}
 */
export function editUserProfile (data) {
  return axios({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}

/**
 * 更改用户头像
 * @param data FromData对象
 * @returns {AxiosPromise}
 */
export function editUserPhoto (data) {
  return axios({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data
  })
}
